package com.xiaoma.lock.spin;

import java.util.concurrent.TimeUnit;

/**
 * 测试自旋锁
 * @author xiaomacdut
 * @date 2020年3月3日 下午12:55:57
 */
public class TestMySpinLock{
    
    public static void main(String [] args){
        MySpinLock mySpinLock = new MySpinLock();
        
        new Thread(()-> {
            mySpinLock.lock();
            try{
                TimeUnit.SECONDS.sleep(1);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            mySpinLock.unLock();
        }, "A").start();
        
        
        new Thread(()-> {
            mySpinLock.lock();
            mySpinLock.unLock();
        }, "B").start();
        
        
    }
}
